<!DOCTYPE html>
<html lang="en">
  <head>
    <title>PseudoTerminalHelpers Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset='utf-8'>
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a name="//apple_ref/swift/Class/PseudoTerminalHelpers" class="dashAnchor"></a>
    <a title="PseudoTerminalHelpers Class Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="../index.html">SwiftTerm 1.0 Docs</a> (65% documented)</p>
        <p class="header-right"><a href="https://github.com/migueldeicaza/SwiftTerm"><img src="../img/gh.png"/>View on GitHub</a></p>
        <p class="header-right"><a href="dash-feed://https%3A%2F%2Fmigueldeicaza%2Egithub%2Eio%2FSwiftTerm%2Fdocsets%2FSwiftTerm%2Exml"><img src="../img/dash.png"/>Install in Dash</a></p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="../index.html">SwiftTerm Reference</a>
        <img id="carat" src="../img/carat.png" />
        PseudoTerminalHelpers Class Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="../Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Classes/Color.html">Color</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/HeadlessTerminal.html">HeadlessTerminal</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/LocalProcess.html">LocalProcess</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/LocalProcessTerminalView.html">LocalProcessTerminalView</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/PseudoTerminalHelpers.html">PseudoTerminalHelpers</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Terminal.html">Terminal</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Terminal/MouseMode.html">– MouseMode</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Terminal/WindowManipulationCommand.html">– WindowManipulationCommand</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/TerminalAccessory.html">TerminalAccessory</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/TerminalDebugView.html">TerminalDebugView</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/TerminalView.html">TerminalView</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/TerminalView/Font.html">– Font</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/TerminalView.html">TerminalView</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/TerminalView/Font.html">– Font</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Enums.html">Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Enums/CursorStyle.html">CursorStyle</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Extensions/TerminalViewDelegate.html">TerminalViewDelegate</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Protocols/LocalProcessDelegate.html">LocalProcessDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/LocalProcessTerminalViewDelegate.html">LocalProcessTerminalViewDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/TerminalDelegate.html">TerminalDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/TerminalViewDelegate.html">TerminalViewDelegate</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Structs.html">Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Structs/Attribute.html">Attribute</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/Attribute/Color.html">– Color</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/CharData.html">CharData</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/CharacterStyle.html">CharacterStyle</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/TerminalOptions.html">TerminalOptions</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/TinyAtom.html">TinyAtom</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Typealiases.html">Type Aliases</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Typealiases.html#/s:9SwiftTerm7TTImagea">TTImage</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            <h1>PseudoTerminalHelpers</h1>
              <div class="declaration">
                <div class="language">
                  <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">PseudoTerminalHelpers</span></code></pre>

                </div>
              </div>
            <p>APIs to assist in controlling a Unix pseudo-terminal from Swift, it provides a wrapper for
the libc <code>forkpty</code>API in the form of <code>fork(andExec:args:env:desiredWindowSize:</code> method,
<code>setWinSize</code> and <code>availableBytes</code></p>

          </section>
          <section class="section task-group-section">
            <div class="task-group">
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:9SwiftTerm21PseudoTerminalHelpersC4fork7andExec4args3env17desiredWindowSizes5Int32V3pid_AJ8masterFdtSgSS_SaySSGANSo7winsizeVztFZ"></a>
                    <a name="//apple_ref/swift/Method/fork(andExec:args:env:desiredWindowSize:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:9SwiftTerm21PseudoTerminalHelpersC4fork7andExec4args3env17desiredWindowSizes5Int32V3pid_AJ8masterFdtSgSS_SaySSGANSo7winsizeVztFZ">fork(andExec:<wbr>args:<wbr>env:<wbr>desiredWindowSize:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>This method both forks and executes the provided command under a Pseudo Terminal, and returns both the process ID and the file descriptor for the pseudo-terminal</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="kd">func</span> <span class="nf">fork</span><span class="p">(</span><span class="nv">andExec</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="nv">args</span><span class="p">:</span> <span class="p">[</span><span class="kt">String</span><span class="p">],</span> <span class="nv">env</span><span class="p">:</span> <span class="p">[</span><span class="kt">String</span><span class="p">],</span> <span class="nv">desiredWindowSize</span><span class="p">:</span> <span class="k">inout</span> <span class="n">winsize</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="p">(</span><span class="nv">pid</span><span class="p">:</span> <span class="n">pid_t</span><span class="p">,</span> <span class="nv">masterFd</span><span class="p">:</span> <span class="kt">Int32</span><span class="p">)?</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>andExec</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the name of the executable to run</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>args</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>arguments to be passed to the executable</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>env</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the environment variables for the child process</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>desiredWindowSize</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the window size that will be set on the pseudo terminal.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/migueldeicaza/SwiftTerm/tree/master/Sources/SwiftTerm/Pty.swift#L64-L80">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:9SwiftTerm21PseudoTerminalHelpersC10setWinSize19masterPtyDescriptor06windowH0s5Int32VAH_So7winsizeVztFZ"></a>
                    <a name="//apple_ref/swift/Method/setWinSize(masterPtyDescriptor:windowSize:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:9SwiftTerm21PseudoTerminalHelpersC10setWinSize19masterPtyDescriptor06windowH0s5Int32VAH_So7winsizeVztFZ">setWinSize(masterPtyDescriptor:<wbr>windowSize:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Sets the window size of the underlying pseudo terminal.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="kd">func</span> <span class="nf">setWinSize</span><span class="p">(</span><span class="nv">masterPtyDescriptor</span><span class="p">:</span> <span class="kt">Int32</span><span class="p">,</span> <span class="nv">windowSize</span><span class="p">:</span> <span class="k">inout</span> <span class="n">winsize</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Int32</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>masterPtyDescriptor</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>a pseudo-terminal master file descriptor, as returned by fork(andExec:)</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>the value from calling the ioctl</p>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/migueldeicaza/SwiftTerm/tree/master/Sources/SwiftTerm/Pty.swift#L87-L90">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:9SwiftTerm21PseudoTerminalHelpersC14availableBytes2fds5Int32V6status_AG4sizetAG_tFZ"></a>
                    <a name="//apple_ref/swift/Method/availableBytes(fd:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:9SwiftTerm21PseudoTerminalHelpersC14availableBytes2fds5Int32V6status_AG4sizetAG_tFZ">availableBytes(fd:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Returns the number of available bytes to be read from the file descriptor</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="kd">func</span> <span class="nf">availableBytes</span><span class="p">(</span><span class="nv">fd</span><span class="p">:</span> <span class="kt">Int32</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="p">(</span><span class="nv">status</span><span class="p">:</span> <span class="kt">Int32</span><span class="p">,</span> <span class="nv">size</span><span class="p">:</span> <span class="kt">Int32</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/migueldeicaza/SwiftTerm/tree/master/Sources/SwiftTerm/Pty.swift#L95-L100">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </section>
        </section>
        <section id="footer">
          <p>&copy; 2020 <a class="link" href="https://tirania.org/" target="_blank" rel="external">Miguel de Icaza</a>. All rights reserved. (Last updated: 2020-05-30)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
